package com.helpfuctions.gcards;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Environment;
import android.view.View;

public class ScreenShot {
	
	private View mScreenShotView;
	private String mImageName = "test.jpg";
	public ScreenShot(View screenShotView) {
		//view with image
		mScreenShotView = screenShotView;
	}
	
	public Bitmap getScreenShot(){
		
		//get Bitmap of all screen
    	View screenView = mScreenShotView.getRootView();
    	//get width and height for Bitmap
    	int width = mScreenShotView.getWidth();
    	int height = mScreenShotView.getHeight();
    	//get start coordinate for Bitmap
    	int x = screenView.getWidth() - width; 
    	int y = screenView.getHeight() - height;
    	screenView.setDrawingCacheEnabled(true);
    	Bitmap screenShot = screenView.getDrawingCache();
    	Bitmap cropedScreenShot = Bitmap.createBitmap(screenShot, x, y, width, height);
    	return cropedScreenShot;
    	/*BitmapDrawable bitmapDrawable =  new BitmapDrawable(cropedScreenShot);
    	mScreenShotView.setBackgroundDrawable(bitmapDrawable);
    	
    	String externalPath = Environment.getExternalStorageDirectory().toString();
    	File storeFile = new File(externalPath, mImageName);
    	FileOutputStream outputFile = null;
    	
    	try {
			outputFile = new FileOutputStream(storeFile);
			cropedScreenShot.compress(Bitmap.CompressFormat.PNG, 100, outputFile);
			outputFile.flush();
			outputFile.close();
		}catch (FileNotFoundException e) {
	        e.printStackTrace();
	    }catch (Exception e) {
	        e.printStackTrace();
	    }*/
    }

}